package net.oschina.team.note.bean;

import com.jfinal.plugin.activerecord.Model;

public class NotesTemplate extends Model<NotesTemplate> {
	private static final long serialVersionUID = -1619067887761928588L;
	public static NotesTemplate ME = new NotesTemplate();
	public static final String TABLENAME = "notes_template";
	
	public static final int STATUS_SHOW = 0;
	public static final int STATUS_HIDE = 1;
	
	public static final String DEFAULT_CONTENT = "即时贴，记录每一个瞬间！";
	
	public static final int DEFAULT_WIDTH = 350;
	public static final int DEFAULT_HEIGHT = 250;
	
	public static final int DEFAULT_TITLE_IMG_WIDTH = 44;//顶部按钉图片的默认宽度
	public static final int DEFAULT_TITLE_IMG_TOP = -20;//顶部按钉图片距离顶部的距离
	
	public static final String DEFAULT_COLOR = "yellow";
	public static final String DEFAULT_TITLE_STYLE = "1";
	
	public static final int DEFAULT_POSITION_X = 300;
	public static final int DEFAULT_POSITION_Y = 300;
	public static final int DEFAULT_POSITION_Z = 0;
	
	/**
	 * 获取指定用户的模版信息
	 * @param user
	 * @return
	 */
	public static NotesTemplate getByUser(long user){
		String sql = "SELECT * FROM " + NotesTemplate.TABLENAME + " WHERE user = ?";
		return ME.findFirst(sql, user);
	}
	
	/**
	 * 为指定用户初始化即时贴模版
	 * @param user
	 * @return
	 */
	public static boolean initByUser(long user){
		int default_title_left = (NotesTemplate.DEFAULT_WIDTH - NotesTemplate.DEFAULT_TITLE_IMG_WIDTH - 10*2)/2;
		return ME.set("user", user).set("content", NotesTemplate.DEFAULT_CONTENT)
		.set("color", NotesTemplate.DEFAULT_COLOR)
		.set("content", NotesTemplate.DEFAULT_CONTENT)
		.set("width", NotesTemplate.DEFAULT_WIDTH)
		.set("height", NotesTemplate.DEFAULT_HEIGHT)
		.set("style_t", NotesTemplate.DEFAULT_TITLE_STYLE)
		.set("title_left", default_title_left)
		.set("title_top", NotesTemplate.DEFAULT_TITLE_IMG_TOP)
		.set("status", NotesTemplate.STATUS_SHOW)
		.set("position_x", NotesTemplate.DEFAULT_POSITION_X)
		.set("position_y", NotesTemplate.DEFAULT_POSITION_Y)
		.set("position_z", NotesTemplate.DEFAULT_POSITION_Z).save();
	}
}
